/*
 * @Author: lclangcheng
 * @Date: 2018-11-01 14:26:20
 * @Last Modified by: lclangcheng
 * @Last Modified time: 2019-11-12 15:54:24
 */

'use strict'

const log = require('../libs/logger')
const BaseComponent = require('./base_component')
const { SiteService } = require('../service')

class Site extends BaseComponent {
  constructor () {
    super()
    this.name = 'site'
    this.getSiteConfigByName = this.getSiteConfigByName.bind(this)
  }

  /**
   * 获取列表
   * @param {Object} ctx
   * @param {Function} next
   */
  async getSiteConfigByName (ctx, next) {
    log.handleLogger(ctx, this.name, this.getSiteConfigByName.name)
    const query = ctx.request.query
    try {
      const res = await SiteService.getSiteConfigByName({ name: query.name })
      ctx.body = { status: 200, data: res }
      next && await next()
    } catch (err) {
      log.errHandleLogger(ctx, this.name, this.getSiteConfigByName.name, err)
      const result = {
        status: err.status || 500,
        message: err.status ? err.message : '服务器内部错误'
      }
      ctx.body = result
    }
  }
}

module.exports = new Site()
